const express = require('express')
const router = express.Router()
const  {logI}  = require('../../log.js')
const moment = require('moment')
const userDb = require('../db/user-db')
const {retError,retSuccess} = require('../../utils/ret')

router
    .post('/',  async (req, res) => {
        let {body: {mac,token,uniqueId}} = req;
        logI("C-S", mac, "TOKEN", `${JSON.stringify(req.body)}`, "null")
        try {
            if(mac && token && uniqueId){
                const time = moment().format('YYYY-MM-DD HH:mm:ss');
                userDb.insertGceToken(mac,token,uniqueId,time,time,uniqueId);
                retSuccess("TOKEN",0,mac,"",res);
            }else{
                retError("TOKEN",10001,"invalid params",res);
            }
        } catch (error) {
            // 处理异常
            retError("TOKEN",10001,error,res);
        }

    })
module.exports = router